function editProfile() {
    document.getElementById('personalInfoFields').disabled = false;
}

function populateUserInfo() {
    var who = JSON.parse(localStorage.getItem("loggedinUser"));
    var users = JSON.parse(localStorage.getItem("users"));

    //find the person who is logged in 
    const user = users.find(u => u.email === who["email"]);

    //fill in the inputs with the values from Local Storage 
    document.getElementById("nameInput").value = user["name"];
    document.getElementById("emailInput").value = user["email"];
}
populateUserInfo();

function saveProfile() {
    const name = document.getElementById('nameInput').value;
    const email = document.getElementById('emailInput').value;

    var who = JSON.parse(localStorage.getItem("loggedinUser"));
    var users = JSON.parse(localStorage.getItem("users"));

    //find the person who is logged in
    const user = users.find(u => u.email === who["email"]);

    user["name"] = name;
    user["email"] = email;

    localStorage.setItem("loggedinUser", JSON.stringify(user));
    localStorage.setItem("users", JSON.stringify(users));

    alert('User Data Saved'); 
    document.getElementById('personalInfoFields').disabled = true;

} 